import { defineStore } from 'pinia'
import { Tag } from '@interface/tag'
export const useTagStore = defineStore('useTagStore', {
  state: (): {
    taglist: Tag[]
  } => {
    return {
      taglist: []
    }
  },
  getters: {},
  actions: {
    pushviewRoute(route: Tag) {
      const tags = this.taglist.find((item) => item.path == route.path) as Tag
      if (!tags) {
        this.taglist.push(route)
      }
    },
    // 删除tag操作
    deltagview(route: Tag) {
      const onindex = this.taglist.findIndex((item) => item.path == route.path)
      this.taglist.splice(onindex, 1)
    }
  },
  persist: {
    enabled: true, //开启数据缓存
    strategies: [
      {
        storage: localStorage, //默认走session
        // 是否存入指定的值
        paths: ['taglist']
      }
    ]
  }
})
